package com.example.baselib.base;

import ohos.aafwk.ability.fraction.Fraction;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.LayoutScatter;
import ohos.agp.window.dialog.ToastDialog;
import ohos.app.Context;
import ohos.bundle.IBundleManager;

public abstract class BaseFraction extends Fraction {

    protected Component mRootComponent;
    protected Context mContext;

    protected abstract int getComponentUIResId();

    protected abstract void initComponent();

    @Override
    protected Component onComponentAttached(LayoutScatter scatter, ComponentContainer container, Intent intent) {
        this.mContext = container.getContext();
        mRootComponent = scatter.parse(getComponentUIResId(), container, false);
        return mRootComponent;
    }

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        try {
            initComponent();
            initData();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    protected void initData() {

    }

    /**
     * 主要获取 ability 的授权消息
     * true 表示拦截,false 表示放行
     */
    public boolean onRequestPermissionsInterceptResult(int requestCode, String[] permissions, int[] grantResults) {
        return false;
    }

    public boolean onAbilityResultIntercept(int requestCode, int resultCode, Intent resultData) {
        return false;
    }

}
